package com.cocoiko.customview;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cocoiko.info.ShopInfo;

public class ShopListAdapter extends ArrayAdapter<ShopInfo> {
	Context context;
	int resource;
	ArrayList<ShopInfo> array;

	public ShopListAdapter(Context context, int textViewResourceId,
			ArrayList<ShopInfo> objects) {
		super(context, textViewResourceId,objects);
		// TODO Auto-generated constructor stub

		this.context = context;
		this.resource = textViewResourceId;
		this.array = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		View view = convertView;
		if (view == null) {
			view = new ShopListItem(context);
		}
		ShopInfo info = array.get(position);

		if (info != null) {

			ImageView shop_icon = ((ShopListItem) view).shop_icon;
			TextView shop_name = ((ShopListItem) view).shop_name;
			TextView shop_address = ((ShopListItem) view).shop_address;

			//if (info.getIcon() != null) {
				shop_icon.setImageBitmap(info.icon);
			//}
			//if (info.getName() != null) {
				shop_name.setText(info.name);
			//}
			//if (info.getAddress() != null) {
				shop_address.setText(info.address);
			//}
		}

		return view;
	}
}
